import {defineStore} from 'pinia'
import request from '@/utils/request'
import { ApiRes,BannerItem, BrandItem, GoodItem, HomeProduct, HotGoods, Special } from '@/types/data'
export default defineStore('home',{
    state() {
        return {
            bannerList:[] as BannerItem[],
            NewList:[] as GoodItem[],
            HotList:[] as HotGoods[],
            BrandList:[] as BrandItem[],
            ProductList:[] as HomeProduct[],
            SpecialList:[] as Special[]
        }
    },
    actions:{
       async getBannerList() {
        const res=await request.get<ApiRes<BannerItem[]>>('/home/banner')
        console.log(res);
        this.bannerList=res.data.result
        },
        async getNewList() {
            const res= await request.get<ApiRes<GoodItem[]>>('/home/new')
            console.log(res);
            this.NewList=res.data.result
        },
        async getHotList() {
                const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
                console.log(res);
                this.HotList=res.data.result
        },
        // 热门品牌
       async getBrandList() {
            const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
            console.log(res);
          this.BrandList=res.data.result
        },
        // 生鲜
       async getProductList() {
            const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
            console.log(res);
            this.ProductList=res.data.result
        },
        async getSpecialList() {
            const res = await request.get<ApiRes<Special[]>>('/home/special')
            console.log(res);
            this.SpecialList=res.data.result
        },
    }
})